<?php
/*
	[Destoon B2B System] Copyright (c) 2008-2013 Destoon.COM
	This is NOT a freeware, use is subject to license.txt
*/
define('DT_NONUSER', true);
require '../../common.inc.php';
require_once DT_ROOT.'/api/geetest/lib/class.geetestlib.php';
require_once DT_ROOT.'/api/geetest/config/config.php';
session_start();
$GtSdk = new GeetestLib(CAPTCHA_ID, PRIVATE_KEY);
$user_id = $_SESSION['user_id'];
$pass = 0;
if ($_SESSION['gtserver'] == 1) {
    $result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $user_id);
    if ($result) $pass = 1;
}else{
    if ($GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode'])) {
        $pass = 1;
    }
}
if($pass) {
	$K = md5($DT_IP.DT_KEY.$_SERVER['HTTP_USER_AGENT']);
	set_cookie('v'.substr($K, 3, 5), $K, $DT_TIME + 86400*7);
	$pageid = get_cookie('pageid');
	$url = DT_PATH;
	if($pageid == 'register') {
		$url = $MODULE[2]['linkurl'].$DT['file_register'].'?forward='.urlencode($MODULE[2]['linkurl']);
	} elseif($pageid == 'my') {
		$url = $MODULE[2]['linkurl'].$DT['file_my'].'?forward='.urlencode($MODULE[2]['linkurl']);
	} elseif($pageid == 'login') {
		$url = $MODULE[2]['linkurl'].$DT['file_login'].'?forward='.urlencode($MODULE[2]['linkurl']);
	}
	set_cookie('pageid', '');
	message('验证成功，感谢您的配合，请继续访问...', $url);
} else {
	message('验证失败，请重试');
}
/*
$K = md5($DT_IP.DT_KEY.$_SERVER['HTTP_USER_AGENT']);
$V = get_cookie('v'.substr($K, 3, 5));
if($K != $V) {
	set_cookie('pageid', 'register');
	exit("<script>window.location.href='/api/geetest/';</script>");
}
*/
?>